package netty.http;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author ：朱博
 * @description：SocketChaneel 通道创建器
 * @date ：2021/4/17 15:30
 */
public class TestServerInitializer extends ChannelInitializer<SocketChannel> {



    /**
     * 初始化Channel的时候方法
     * @param ch
     * @throws Exception
     */
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {

        //获取管道
        ChannelPipeline pipeline = ch.pipeline();
        //添加默认的Http解码器
        pipeline.addLast("MyHttpServerCodec",new HttpServerCodec());

        //增加自定义的处理器
        pipeline.addLast("MyTestHttpServerHandler",new TestHttpServerHandler());
    }
}
